package com.tu.images;

import it.sephiroth.android.library.imagezoom.ImageViewTouch;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.MenuItem.OnMenuItemClickListener;
import android.view.View;

import com.googlecode.flickrjandroid.photos.Photo;
import com.googlecode.flickrjandroid.photos.PhotoList;
import com.tu.images.ImageUtils.DownloadedDrawable;
import com.tu.tasks.ImageDownloadTask;

public class MyPagerAdapter extends PagerAdapter {
	
	private Activity activity;
	private PhotoList photos;
	public MyPagerAdapter(Activity a, PhotoList d) {
		activity = a;
        photos = d;
	}

	@Override
	public void destroyItem(View view, int arg1, Object object) {
		
	}

	@Override
	public void finishUpdate(View arg0) {

	}

	@Override
	public int getCount() {
		return photos.size();
	}

	@Override
	public Object instantiateItem(View view, int position) {
		Log.d("Vi tri", position+"");
		Photo photo = photos.get(position);
		ImageViewTouch imgTouch = new ImageViewTouch(activity,null);
		ImageDownloadTask task = new ImageDownloadTask(imgTouch);
		Drawable drawable = new DownloadedDrawable(task);
		imgTouch.setImageDrawable(drawable);
		task.execute(photo.getLargeUrl());
		((ViewPager) view).addView(imgTouch);
		return imgTouch;
	}

	@Override
	public boolean isViewFromObject(View view, Object object) {
		return view == object;
	}

	
	
	@Override
	public void restoreState(Parcelable arg0, ClassLoader arg1) {

	}

	@Override
	public Parcelable saveState() {
		return null;
	}

	@Override
	public void startUpdate(View arg0) {

	}

}
